FROM php:8.1-fpm-alpine

# substitution of domestic sources
RUN cp /etc/apk/repositories /etc/apk/repositories.bak \
&& sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
&& apk update && apk upgrade \
&& apk add --no-cache libpng-dev libwebp-dev freetype-dev libjpeg-turbo-dev libmcrypt-dev imagemagick-dev libxml2-dev libzip-dev postgresql-dev rabbitmq-c-dev autoconf g++ make

# install php extension
RUN docker-php-ext-install -j$(nproc) bcmath exif pcntl soap sockets zip pdo_mysql pdo_pgsql \
&& docker-php-ext-configure gd --with-freetype=/usr/include/freetype2/ --with-jpeg=/usr/include/ --with-webp=/usr/include/webp \
&& docker-php-ext-install -j$(nproc) gd

COPY pear /tmp/pear

# redis
RUN pecl install /tmp/pear/redis-6.0.2.tgz && docker-php-ext-enable redis

# mongodb
RUN pecl install /tmp/pear/mongodb-1.17.1.tgz && docker-php-ext-enable mongodb

# swoole
RUN pecl install /tmp/pear/swoole-5.1.1.tgz && docker-php-ext-enable swoole

# rabbitmq
RUN pecl install /tmp/pear/amqp-2.1.1.tgz && docker-php-ext-enable amqp

# install composer
COPY composer.phar /usr/local/bin/composer
RUN composer config -g repos.packagist composer https://mirrors.tencent.com/composer/

# delete tmp files
RUN rm -rf /tmp/pear